﻿/** 龙与地下城1

  By setycyas @2023-02-06
*/

/* 全局设定
*/
#Warn
#MaxThreadsPerHotkey 1
SetWorkingDir(A_ScriptDir)
#Include "..\Class\FaceDetector.2.ahk"
#Include "..\Class\CommonMacro.2.ahk"
#Include "..\Class\CommonUI.2.ahk"
#Include "..\Class\MyFuns.2.ahk"
#Include "..\Class\MyEmu.2.ahk"
SendMode("Input")

/* 制作龙与地下城1的宏类
*/
class DND1Macro extends CommonMacro {

  /* 新增的宏函数
  */
  /*
  _下蹲(key){
    MyFuns.keyDown("down")
    sleep(50)
    this._down(2)
    sleep(50)
    MyFuns.keyUp("down")
  }
  */
  _蹲站(key){
    if (GetKeyState(this._keys[2])){ ;GetKeyState()缺省第二参数,可获取"程序以为"的按键状态,实用!
      this._up(2)
    } else {
      MyFuns.keyDown("down")
      sleep(50)
      this._down(2)
      sleep(50)
      MyFuns.keyUp("down")
    }
  }
  _前A或滑斩(key){
    if (GetKeyState(this._keys[2])){ ;检测到按住了B键则用滑斩,否则前A
      this._蹲后滑斩(key)
    } else {
      this._前A(key)
    }
  }
  _蹲后滑斩(key){
    local face := this._face.face()
    this._up(2)
    sleep(20)
    MyFuns.pressKeys([face, this._keys[1]], [25, 50])
  }
  _蹲后滑行(key){
    local face := this._face.face()
    this._up(2)
    sleep(20)
    MyFuns.pressKeys([face, this._keys[2]], [25, 50])
  }
  _左右摇(key){
    local thisKey :=  MyFuns.getHotkey(key) ;触发技能的热键
    while (GetKeyState(thisKey, "P")) {
      MyFuns.press("right", 20)
      sleep(20)
      MyFuns.press("left", 20)
      sleep(20)
    }
  }

  /* 重载宏接口
  */
  _setMacro(){
    this.macroMap["连发A"] := this._连发A.bind(this)
    this.macroMap["蹲站"] := this._蹲站.bind(this)
    ;this.macroMap["蹲后滑斩"] := this._蹲后滑斩.bind(this)
    ;this.macroMap["蹲后滑行"] := this._蹲后滑行.bind(this)
    this.macroMap["前A或滑斩"] := this._前A或滑斩.bind(this)
    this.macroMap["蹲后滑行"] := this._蹲后滑行.bind(this)
    this.macroMap["A后防御"] := this._A后防御.bind(this)
    this.macroMap["左右摇"] := this._左右摇.bind(this)
    ;this.macroArr := ["连发A", "蹲站", "蹲后滑斩", "蹲后滑行", "A后防御", "左右摇"]
    this.macroArr := ["连发A", "蹲站", "前A或滑斩", "蹲后滑行", "A后防御", "左右摇"]
  }

}

/* 运行当前脚本
*/
if (A_ScriptName == "龙与地下城1.2.ahk") {
  face := FaceDetector() ;方向检测对象
  macro := DND1Macro(face, ["x","e"]) ;宏对象,有界面时第二个参数可以随便写但长度不要小于2
  ;宏方案预设,用于菜单
  preset := Map("默认", ["连发A", "前A或滑斩", "蹲站", "A后防御", "蹲后滑行", "左右摇"])
  ;新建界面并设定
  ui := CommonUI("龙与地下城1", macro ,preset)
  ui.setup()
  ui._exeComboBox.Choose(MyEmu.WINKAWAKS)
  ui._hotkeyEdit.Text := "w,q,2,3,r,a"
  ui._fpsEdit.Text := 4
  ui.readPresetMenu("默认")
}